// 班级表
module.exports = app=>{
    const {STRING,INTEGER,DATE} = app.Sequelize;
    const Class = app.model.define('class',{
        name:{
            type:STRING,
            primaryKey: true, // 是否为主键
            allowNull: false,
            comment:'班级名称'
        },
        project_name:{
            type:STRING,
            allowNull: false,
            comment:'所属项目'
        },
        user_name:{
            type:STRING,
            comment:'班主任'
        },
        state:{
            type:STRING,
            allowNull: false,
            comment:'状态'
        },
    })
    Class.associate = function () {
        //所属项目关联
        app.model.Class.belongsTo(app.model.Project, {
          foreignKey: 'project_name',
          targetKey:'name',
          as:'project' 
        })

        app.model.Class.belongsTo(app.model.User, {
          foreignKey: 'user_name',
          targetKey:'name',
          as:'user'
        })
    }
    return Class
}